﻿using System;
using System.Collections.Generic;
using System.Text;
using Axis.Dao.Base;
using FWS.Framework.Log;
using Axis.Dao.SQL;
using Axis.BusinessObject.Core;
using Axis.BusinessObject.Response;

namespace Axis.Dao.Core
{
    public class CCoreDao : CDaoBase
    {
        /// <summary>
        /// "<InputValue LoginName=\"Admin\" Password=\"admin\"/>"
        /// </summary>
        /// <param name="pInputValue"></param>
        /// <returns></returns>
        public CLoginResponse Login(string pInputValue)
        {
            try
            {
                COutputValue output = new COutputValue();
                IList<CUserList> list = CallFunctionWithList<CUserList>(CSystemFunction.Login, pInputValue, ref output);
                CLoginResponse loginResponse = new CLoginResponse();
                loginResponse.Code = output.Code;
                loginResponse.Name = output.Name;
                loginResponse.Description = output.Description;
                loginResponse.Result = output.Result;

                if (loginResponse.IsSuccessfull && list != null && list.Count > 0)
                {
                    loginResponse.UserList = list[0];
                }

                return loginResponse;

            }
            catch (Exception ex)
            {
                CLogManager.WriteDAL("CItemsDao", ex.Message);
                return null;
            }
        }

        /// <summary>
        /// "<InputValue LoginName=\"Admin\" Password=\"admin\"/>"
        /// </summary>
        /// <param name="pInputValue"></param>
        /// <returns></returns>
        public CMemberLoginResponse MemberLogin(string pInputValue)
        {
            try
            {
                COutputValue output = new COutputValue();
                IList<CMemberList> list = CallFunctionWithList<CMemberList>(CSystemFunction.MemberLogin, pInputValue, ref output);
                CMemberLoginResponse loginResponse = new CMemberLoginResponse();
                loginResponse.Code = output.Code;
                loginResponse.Name = output.Name;
                loginResponse.Description = output.Description;
                loginResponse.Result = output.Result;

                if (loginResponse.IsSuccessfull && list != null && list.Count > 0)
                {
                    loginResponse.Member = list[0];
                }
               
                return loginResponse;

            }
            catch (Exception ex)
            {
                CLogManager.WriteDAL("CItemsDao", ex.Message);
                return null;
            }
        }

        /// <summary>
        /// InputValue UserID="1" ID="1" PageIndex="1" RowsPerPage ="20"
        /// </summary>
        /// <param name="pInputValue"></param>
        /// <returns></returns>
        public IList<CUserList> GetUserList(string pInputValue)
        {
            try
            {
                COutputValue output = new COutputValue();
                IList<CUserList> list = CallFunctionWithList<CUserList>(CSystemFunction.GetUserList, pInputValue, ref output);
                LastOutputValue = output;
                
                return list;

            }
            catch (Exception ex)
            {
                CLogManager.WriteDAL("CItemsDao", ex.Message);
                return null;
            }
        }

        /// <summary>
        /// <InputValue UserID="1" Session="" FunctionCode="Gender" />
        /// FunctionCode cu the se dua khi phat sinh nghiep vu
        /// </summary>
        /// <param name="pInputValue"></param>
        /// <returns></returns>
        public IList<CListData> GetListData(string pInputValue)
        {
            try
            {
                COutputValue output = new COutputValue();
                IList<CListData> list = CallFunctionWithList<CListData>(CSystemFunction.GetListData, pInputValue, ref output);
                LastOutputValue = output;
                return list;

            }
            catch (Exception ex)
            {
                CLogManager.WriteDAL("CItemsDao", ex.Message);
                return null;
            }
        }

        /// <summary>
        /// <InputValue UserID="1" Session="" Action="INSERT|DELETE|UPDATE"  ID="1" LoginName="" Password="" Session="" FullName="" Email="" CMND="" IssueDate="" IssuePlace="" Phone="" Type="" Class="" Mark="" DateOfBirth="" Gender="0" Job="" Address="" Ward="" Province="" Education=""/>
        /// <InputValue Action="VERIFY" ID="1" VerifyCode=""/>
        /// <InputValue UserID="1" Session="" Action="CHECK" Email="check@gmail.com" />
        /// </summary>
        /// <param name="pInputValue"></param>
        /// <returns></returns>
        public CApplicationMessage ActionUserList(string pInputValue)
        {
            try
            {
                COutputValue output = new COutputValue();
                CApplicationMessage list = CallFunction<CApplicationMessage>(CSystemFunction.ActionUserList, pInputValue);
                return list;

            }
            catch (Exception ex)
            {
                CLogManager.WriteDAL("CItemsDao", ex.Message);
                return null;
            }
        }

        /// <summary>
        /// <InputValue UserID="1" Session="" DataCode="Job" Action="INSERT|DELETE|UPDATE" ID="1" Code="" Name="" Description="" ParentID="1"/>
        /// </summary>
        /// <param name="pInputValue"></param>
        /// <returns></returns>
        public CApplicationMessage ActionListData(string pInputValue)
        {
            try
            {
                COutputValue output = new COutputValue();
                CApplicationMessage list = CallFunction<CApplicationMessage>(CSystemFunction.ActionListData, pInputValue);
                return list;

            }
            catch (Exception ex)
            {
                CLogManager.WriteDAL("CItemsDao", ex.Message);
                return null;
            }
        }

        /// <summary>
        /// <InputValue UserID="1" Session="" Action="INSERT|DELETE|UPDATE"  ID="1" LoginName="" Password="" Session="" FullName="" Email="" CMND="" IssueDate="" IssuePlace="" Phone="" Type="" Class="" Mark="" DateOfBirth="" Gender="0" Job="" Address="" Ward="" Province="" Education=""/>
        /// <InputValue Action="VERIFY" ID="1" VerifyCode=""/>
        /// <InputValue UserID="1" Session="" Action="CHECK" Email="check@gmail.com" />
        /// </summary>
        /// <param name="pInputValue"></param>
        /// <returns></returns>
        public CApplicationMessage ActionMemberList(string pInputValue)
        {
            try
            {
                COutputValue output = new COutputValue();
                CApplicationMessage list = CallFunction<CApplicationMessage>(CSystemFunction.ActionMemberList, pInputValue);
                return list;

            }
            catch (Exception ex)
            {
                CLogManager.WriteDAL("CItemsDao", ex.Message);
                return null;
            }
        }
        /// <summary>
        /// InputValue UserID="1" ID="1" PageIndex="1" RowsPerPage ="20"
        /// </summary>
        /// <param name="pInputValue"></param>
        /// <returns></returns>
        public IList<CMemberList> GetMemberList(string pInputValue)
        {
            try
            {
                COutputValue output = new COutputValue();
                IList<CMemberList> list = CallFunctionWithList<CMemberList>(CSystemFunction.GetMemberList, pInputValue, ref output);
                LastOutputValue = output;

                return list;

            }
            catch (Exception ex)
            {
                CLogManager.WriteDAL("CItemsDao", ex.Message);
                return null;
            }
        }

        /// <summary>
        /// InputValue UserID="1" ID="1" PageIndex="1" RowsPerPage ="20"
        /// </summary>
        /// <param name="pInputValue"></param>
        /// <returns></returns>
        public CDataTable GetMemberListExport(string pInputValue)
        {
            try
            {
                COutputValue output = new COutputValue();
                CDataTable list = CallFunctionWithDataTable(CSystemFunction.GetMemberList, pInputValue);
                LastOutputValue = output;

                return list;

            }
            catch (Exception ex)
            {
                CLogManager.WriteDAL("CItemsDao", ex.Message);
                return null;
            }
        }

        /// <summary>
        /// <InputValue UserID="1" Session="" Action="INSERT|DELETE|UPDATE"  ID="1" LoginName="" Password="" Session="" FullName="" Email="" CMND="" IssueDate="" IssuePlace="" Phone="" Type="" Class="" Mark="" DateOfBirth="" Gender="0" Job="" Address="" Ward="" Province="" Education=""/>
        /// <InputValue Action="VERIFY" ID="1" VerifyCode=""/>
        /// <InputValue UserID="1" Session="" Action="CHECK" Email="check@gmail.com" />
        /// </summary>
        /// <param name="pInputValue"></param>
        /// <returns></returns>
        public CApplicationMessage ActionGroupUser(string pInputValue)
        {
            try
            {
                COutputValue output = new COutputValue();
                CApplicationMessage list = CallFunction<CApplicationMessage>(CSystemFunction.ActionGroupUser, pInputValue);
                return list;

            }
            catch (Exception ex)
            {
                CLogManager.WriteDAL("CItemsDao", ex.Message);
                return null;
            }
        }
    }
}
